#include "user.h"

user::user()
{

}

user::user(std::string name,std::string pwd)
{
    this->username = name;
    this->password = pwd;
}

bool user::CheckPassword(std::string pwd)
{
    if(pwd == this->password)
        return 1;
    else 
        return 0;
}

bool user::ChangePassword(std::string oldpwd,std::string newpwd)
{
    if(oldpwd == this->password)
    {
        this->password = newpwd;
        return 1;
    }
    else 
        return 0;
}

void user::borrowbook(book* book)
{
    borrowedbooks.emplace_back(book);
}

bool user::returnbook(book* book)
{
    for(int i = 0;i < borrowedbooks.size(); i++)
    {
        if(*book == *(borrowedbooks[i]))
        {
            borrowedbooks.erase(borrowedbooks.begin() + i);
            return 1;
        }
    }
    return 0;
}